/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.ProdManage;
import com.yami.shop.common.annotation.SysLog;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.ProdManageService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 商品分组
 *
 * @author hzm
 * @date 2019-04-18 09:08:36
 */
@RestController
@RequestMapping("/prod/manage")
public class ProdManageController {

    @Autowired
    private ProdManageService prodManageService;

    /**
     * 分页查询
     *
     * @param page    分页对象
     * @return 分页数据
     */
    @GetMapping("/page")
    public ResponseEntity<IPage<ProdManage>> getPage(PageParam<ProdManage> page, ProdManage manage) {
        IPage<ProdManage> prodManagePage = prodManageService.page(
                page, new LambdaQueryWrapper<ProdManage>()
                        .eq(manage.getProductType() != null, ProdManage::getProductType, manage.getProductType())
                        .eq(StringUtils.isNotBlank(manage.getProviderCode()), ProdManage::getProviderCode, manage.getProviderCode())
                        .like(StringUtils.isNotBlank(manage.getProductName()), ProdManage::getProductName, manage.getProductName()));
        return ResponseEntity.ok(prodManagePage);

    }


    /**
     * 通过id查询商品分组标签
     *
     * @param id id
     * @return 单个数据
     */
    @GetMapping("/info/{id}")
    public ResponseEntity<ProdManage> getById(@PathVariable("id") String id) {
        return ResponseEntity.ok(prodManageService.getById(id));
    }

    /**
     * 修改商品分组标签
     * @return 是否修改成功
     */
    @SysLog("修改商品分组标签")
    @PutMapping
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid List<ProdManage> list) {
        return ResponseEntity.ok(prodManageService.updateBatchById(list));
    }




}